package org.com.myfb.toolimpl;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.com.myfb.tool.ToolInter;

public class ToolImpl implements ToolInter {
	/**
	 * @category 把默认 Date格式转化成 "yyyy-MM-dd HH:mm:ss"字符串
	 * 
	 * @param date
	 * @return "yyyy-MM-dd HH:mm:ss"格式字符串
	 */
	public String dateToString(Date date) {
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String dateString = null;
		if (date != null) {
			dateString = df.format(date);
			return dateString;
		}
		return "";
	}
	/**
	 * @category 把默认Date的格式转化成 "yyyy-MM-dd "格式字符串
	 * @param date
	 * @return "yyyy-MM-dd"格式字符串
	 */
	public String dateToString1(Date date) {

		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		String dateString = null;
		if (date != null) {
			dateString = df.format(date);
			return dateString;
		}
		return "";
	}

	/**
	 *将"yyyy-MM-dd HH:mm:ss"格式的字符串转换成Date
	 * @param date
	 * @return Date
	 */
	public Date stringToDate(String date) {
		SimpleDateFormat simple = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date dateDate = null;
		if ( date==null || date.equals("")  ) {
			return dateDate;
		} else {
			try {
				dateDate = simple.parse(date);
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return dateDate;
		}
	}
	/**
	 * @category 将"yyyy-MM-dd"格式的字符串转换成Date
	 * @param date
	 * @return Date
	 */
	public Date stringToDate2(String date) {
		SimpleDateFormat simple = new SimpleDateFormat("yyyy-MM-dd");
		Date dateDate = null;
		if (date==null || date.equals("")  ) {
			return dateDate;
		} else {
			try {
				dateDate = simple.parse(date);
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return dateDate;
		}
	}
	/**
	 * @category 将"yyyy-MM-dd'T'HH:mm"格式的字符串转换成Date
	 * @param date 要转换的字符串
	 * @return Date
	 */
	public Date stringWithTtoDate(String date) {
		SimpleDateFormat simple = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");
		Date dateDate = null;
		if (date==null || date.equals("")  ) {
			return dateDate;
		} else {
			try {
				dateDate = simple.parse(date);
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return dateDate;
		}
	}
}
